﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace iseeqq
{
    class KeyBoard
    {

        public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key click flag
        public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
        [DllImport("user32.dll")]
        private static extern void keybd_event(byte bVk, byte bSCan, int dwFlags, int dwExtraInfo);
        [DllImport("user32.dll")]
        private static extern byte MapVirtualKey(byte wCode, int wMap);

        public static void KeyDown(VirtualKeyCode keyCode)
        {
            var code = (byte)keyCode;
            keybd_event(code, 0, 0, 0);
        }

        public static void KeyUp(VirtualKeyCode keyCode)
        {
            var code = (byte)keyCode;
            keybd_event(code, 0, KEYEVENTF_KEYUP, 0);
        }

        public static void KeyDownAndUp(VirtualKeyCode keyCode)
        {
            var code = (byte)keyCode;
            keybd_event(code, 0, KEYEVENTF_EXTENDEDKEY, 0);
        }
    }
}
